
module.exports = Behavior({
    attached() {
        this.formItemMap = {};
        this.modelMap = new Map();
        // console.log('attached');
    },
    methods: {
        setFormItem(name, ctx) {
            this.formItemMap[name] = ctx;
        },
        getModel() {
            let entries = [...this.modelMap.entries()]
            let obj = Object.fromEntries(entries)
            return obj
        },
        setModel(obj = {}, {handle} = {}) {
            let self = this;
            Object.keys(obj).forEach(key => {
                self.setModelByName(key, obj[key])
    // console.log(self)
                if (self.formItemMap[key]) {
                    if (self.formItemMap[key].onInitModel) {
                        self.formItemMap[key].onInitModel(obj[key], handle)
                    }
                }
            });

        },
        setModelByName(name, val) {
            this.modelMap.set(name, val);
            // console.log('model', model);
        },
    }
})